﻿<!--=================================================================
Copyright (C) Microsoft Corporation.  All rights reserved.
==================================================================-->

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:dg="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit"
                    xmlns:dgp="clr-namespace:Microsoft.Windows.Controls.Primitives;assembly=WPFToolkit"
                    xmlns:converters="clr-namespace:LockCrypt.Converters">
    <converters:BoolToOpacityConverter x:Key="BoolToOpacityConverter" />
    <converters:ObjectToTypeName x:Key="ObjectToTypeName" />

    <!--
  *****************************************************************************
  STYLES AND TEMPLATES
  *****************************************************************************
  -->

    <!-- Column Header -->
    <BooleanToVisibilityConverter x:Key="bool2VisibilityConverter" />
    <!-- DataGridColumnHeader Right Gripper Style -->
    <Style x:Key="ColumnHeaderRightGripperStyle" TargetType="{x:Type Thumb}">
        <Setter Property="Width" Value="8"/>
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="Cursor" Value="SizeWE"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Thumb}">
                    <Border Padding="{TemplateBinding Padding}"
							Background="{TemplateBinding Background}">
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <!-- DataGridColumnHeader Left Gripper Style -->
    <Style x:Key="ColumnHeaderLeftGripperStyle" 
		   BasedOn="{StaticResource ColumnHeaderRightGripperStyle}" 
		   TargetType="{x:Type Thumb}">
        <Setter Property="Width" Value="8"/>
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="Cursor" Value="SizeWE"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Thumb}">
                    <Border Name="Border"
							Padding="{TemplateBinding Padding}" 
							Background="{TemplateBinding Background}">
                        <Canvas>
                            <Line RenderOptions.EdgeMode="Aliased" Stroke="#88B0E4"
								  X1="7" Y1="{Binding ElementName=Border, Path=ActualHeight}"
								  X2="7" Y2="0"/>
                        </Canvas>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <!-- DataGridColumnHeader Style -->
    <Style x:Key="ColumnHeaderStyle" TargetType="{x:Type dgp:DataGridColumnHeader}">
        <Setter Property="VerticalContentAlignment" Value="Center" />
        <Setter Property="Background" Value="{StaticResource HeaderBackgroundBrush}"/>
        <Setter Property="BorderBrush" Value="{StaticResource HeaderBorderBrush}" />
        <Setter Property="BorderThickness" Value="0,1,0,1" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type dgp:DataGridColumnHeader}">
                    <Grid>
                        <dg:DataGridHeaderBorder
							x:Name="headerBorder"
							SortDirection="{TemplateBinding SortDirection}"
							IsHovered="{TemplateBinding IsMouseOver}"
							IsPressed="{TemplateBinding IsPressed}"
							IsClickable="{TemplateBinding CanUserSort}"
							Background="{TemplateBinding Background}"
							BorderBrush="{TemplateBinding BorderBrush}"
							BorderThickness="{TemplateBinding BorderThickness}"
							Padding ="{TemplateBinding Padding}"
							SeparatorVisibility="{TemplateBinding SeparatorVisibility}"
							SeparatorBrush="{TemplateBinding SeparatorBrush}">
                            <Border BorderBrush="{StaticResource HeaderInnerBorderBrush}" 
									BorderThickness="0,1,0,0">
                                <TextBlock
									Text="{Binding}" Margin="4,0,4,0"
									SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
									VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
									HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" />
                            </Border>
                        </dg:DataGridHeaderBorder>

                        <Thumb x:Name="PART_LeftHeaderGripper"
							   HorizontalAlignment="Left"
							   Style="{StaticResource ColumnHeaderRightGripperStyle}"/>
                        <Thumb x:Name="PART_RightHeaderGripper"
							   HorizontalAlignment="Right"
							   Style="{StaticResource ColumnHeaderLeftGripperStyle}"/>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="headerBorder" Property="Background" 
									Value="{StaticResource HeaderHighlightedBackgoundBrush}" />
                        </Trigger>
                        <Trigger Property="IsPressed" Value="True">
                            <Setter TargetName="headerBorder" Property="Background" 
									Value="{StaticResource HeaderPressedBackgroundBrush}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <!-- Right Aligned DataGridColumnHeader Style-->
    <Style x:Key="RightAlignedColumnHeaderStyle" 
           TargetType="{x:Type dgp:DataGridColumnHeader}"
           BasedOn="{StaticResource ColumnHeaderStyle}">
        <Setter Property="HorizontalContentAlignment" Value="Right"/>
    </Style>
    <!-- Center Aligned DataGridColumnHeader Style-->
    <Style x:Key="CenterAlignedColumnHeaderStyle" 
           TargetType="{x:Type dgp:DataGridColumnHeader}"
           BasedOn="{StaticResource ColumnHeaderStyle}">
        <Setter Property="HorizontalContentAlignment" Value="Center"/>
    </Style>

    <!-- DataGridRowHeader Gripper -->
    <Style x:Key="RowHeaderGripperStyle" TargetType="{x:Type Thumb}">
        <Setter Property="Height" Value="8"/>
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="Cursor" Value="SizeNS"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Thumb}">
                    <Border Padding="{TemplateBinding Padding}"
							Background="{TemplateBinding Background}"/>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <!-- DataGridRowHeader Style -->
    <Style x:Key="{x:Type dgp:DataGridRowHeader}"
		   TargetType="{x:Type dgp:DataGridRowHeader}">
        <Setter Property="Background" Value="{StaticResource HeaderBackgroundBrush}" />
        <Setter Property="BorderBrush" Value="{StaticResource HeaderBorderBrush}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type dgp:DataGridRowHeader}">
                    <Grid>
                        <dg:DataGridHeaderBorder 
							x:Name="headerBorder"
							IsSelected="{TemplateBinding IsRowSelected}"
							IsHovered ="{TemplateBinding IsMouseOver}"
							IsPressed="{TemplateBinding IsPressed}"
							Background="{TemplateBinding Background}"
							BorderBrush="{TemplateBinding BorderBrush}"
							BorderThickness="1,0,1,1"
							Padding ="{TemplateBinding Padding}"
							Orientation="Horizontal"
							SeparatorVisibility="{TemplateBinding SeparatorVisibility}"
							SeparatorBrush="{TemplateBinding SeparatorBrush}">
                            <Border BorderBrush="{StaticResource HeaderInnerBorderBrush}"
									BorderThickness="0,1,0,0">
                                <StackPanel Orientation="Horizontal">
                                    <ContentPresenter
										SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
										VerticalAlignment="Center"/>
                                    <Control
										SnapsToDevicePixels="false"
										Visibility="{Binding RelativeSource={RelativeSource AncestorType={x:Type dg:DataGridRow}}, Path=(Validation.HasError), Converter={StaticResource bool2VisibilityConverter}}"
										Template="{Binding RelativeSource={RelativeSource AncestorType={x:Type dg:DataGridRow}}, Path=ValidationErrorTemplate}" />
                                </StackPanel>
                            </Border>
                        </dg:DataGridHeaderBorder>

                        <Thumb x:Name="PART_TopHeaderGripper"
							   VerticalAlignment="Top"
							   Style="{StaticResource RowHeaderGripperStyle}"/>
                        <Thumb x:Name="PART_BottomHeaderGripper"
							   VerticalAlignment="Bottom"
							   Style="{StaticResource RowHeaderGripperStyle}"/>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="headerBorder" Property="Background" 
									Value="{StaticResource HeaderHighlightedBackgoundBrush}" />
                        </Trigger>
                        <Trigger Property="IsPressed" Value="True">
                            <Setter TargetName="headerBorder" Property="Background" 
									Value="{StaticResource HeaderPressedBackgroundBrush}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!-- DataGridCell -->
    
    <Style x:Key="{x:Type dg:DataGridCell}" TargetType="{x:Type dg:DataGridCell}">
        <Setter Property="OverridesDefaultStyle" Value="True" />
        <Setter Property="BorderThickness" Value="0" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type dg:DataGridCell}">
                    <Border x:Name="BackgroundBorder" Background="Transparent" BorderThickness="0">
                        <ContentPresenter VerticalAlignment="Center" Margin="4,0,6,0" />
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsSelected" Value="True">
                            <!--Setter TargetName="BackgroundBorder" Property="Background" Value="{StaticResource Brush_DataGridSelected}" />
                            <Setter Property="BorderBrush" Value="{StaticResource Brush_DataGridSelected}" /-->
                            <!--Setter TargetName="BackgroundBorder" Property="Background" Value="{StaticResource BtnOverFill}" />
                            <Setter Property="BorderBrush" Value="{StaticResource selectedStroke}" /-->
                            <Setter TargetName="BackgroundBorder" Property="TextElement.Foreground" Value="{StaticResource Brush_DataGridSelectedForeground}" />
                            <Setter Property="Foreground" Value="Black" />
                            <!--Setter TargetName="Details" Property="Visibility" Value="Visible" /-->
                        </Trigger>
                        <Trigger Property="dg:DataGridRow.IsFocused" Value="True">
                            <Setter TargetName="BackgroundBorder" Property="Background" Value="{StaticResource BtnOverFill}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!-- DataGridRow -->

    <Style x:Key="{x:Type dg:DataGridRow}" TargetType="{x:Type dg:DataGridRow}">
        <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" />
        <Setter Property="SnapsToDevicePixels" Value="true"/>
        <Setter Property="BorderThickness" Value="1"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type dg:DataGridRow}">
                    <Border x:Name="Border" Background="Transparent" BorderThickness="1" SnapsToDevicePixels="True">
                        <Border Name="InnerBorder" Background="Transparent" IsHitTestVisible="True" SnapsToDevicePixels="true" CornerRadius="1" BorderThickness="0">
                            <dgp:SelectiveScrollingGrid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="*"/>
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                </Grid.RowDefinitions>
                                <dgp:DataGridCellsPresenter Grid.Column="1" ItemsPanel="{TemplateBinding ItemsPanel}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                                <dgp:DataGridRowHeader dgp:SelectiveScrollingGrid.SelectiveScrollingOrientation="Vertical" Grid.RowSpan="2" Visibility="{Binding RelativeSource={RelativeSource AncestorType={x:Type dg:DataGrid}}, Path=HeadersVisibility, Converter={x:Static dg:DataGrid.HeadersVisibilityConverter}, ConverterParameter={x:Static dg:DataGridHeadersVisibility.Row}}"/>
                                <Grid Grid.Column="1" Grid.Row="1" Name="Details" Visibility="Collapsed" Background="Gray">
                                    <dgp:DataGridDetailsPresenter />
                                </Grid>
                            </dgp:SelectiveScrollingGrid>
                        </Border>
                    </Border>
                    <ControlTemplate.Triggers>
                            <Trigger Property="IsSelected" Value="true">
                                <Setter TargetName="InnerBorder" Property="Background" Value="{StaticResource SelectedBackgroundBrush}"/>
                                <Setter TargetName="InnerBorder" Property="BorderBrush" Value="{StaticResource SelectedBorderBrush}"/>
                                <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource SelectedBorderBrushDark}"/>
                                <Setter TargetName="InnerBorder" Property="BorderThickness" Value="1"/>
                            </Trigger>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
                            </Trigger>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter TargetName="InnerBorder" Property="Background" Value="{StaticResource SelectedBackgroundBrushDark}"/>
                                <!--Setter TargetName="InnerBorder" Property="BorderBrush" Value="{StaticResource MouseOverBorderBrush}"/-->
                                <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource MouseOverBorderBrushDark}"/>
                            </Trigger>
                            <MultiTrigger>
                                <MultiTrigger.Conditions>
                                    <Condition Property="IsFocused" Value="False"/>
                                    <Condition Property="IsSelected" Value="True"/>
                                </MultiTrigger.Conditions>
                                <MultiTrigger.Setters>
                                    <Setter TargetName="InnerBorder" Property="Background" Value="{StaticResource SelectedUnfocusedBackgroundBrushDark}"/>
                                    <Setter TargetName="InnerBorder" Property="BorderBrush" Value="{StaticResource SelectedUnfocusedBorderBrush}"/>
                                    <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource SelectedUnfocusedBorderBrushDark}"/>
                                </MultiTrigger.Setters>
                            </MultiTrigger>
                            <MultiTrigger>
                                <MultiTrigger.Conditions>
                                    <Condition Property="ItemsControl.AlternationIndex" Value="0"/>
                                    <Condition Property="IsMouseOver" Value="false"/>
                                </MultiTrigger.Conditions>
                                <MultiTrigger.Setters>
                                    <Setter Property="Background" Value="{StaticResource AlternationBrush1}" TargetName="InnerBorder" />
                                </MultiTrigger.Setters>
                            </MultiTrigger>
                            <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="ItemsControl.AlternationIndex" Value="1"/>
                                <Condition Property="IsMouseOver" Value="false"/>
                            </MultiTrigger.Conditions>
                            <MultiTrigger.Setters>
                                <Setter Property="Background" Value="{StaticResource AlternationBrush2}" TargetName="InnerBorder" />
                            </MultiTrigger.Setters>
                        </MultiTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <!--Style.Triggers>
            <Trigger Property="ItemsControl.AlternationIndex" Value="0">
                <Setter Property="Background" Value="{StaticResource AlternationBrush1}" />
            </Trigger>
            <Trigger Property="ItemsControl.AlternationIndex" Value="1">
                <Setter Property="Background" Value="{StaticResource AlternationBrush2}" />
            </Trigger>
            <Trigger Property="ItemsControl.AlternationIndex" Value="2">
                <Setter Property="Background" Value="{StaticResource AlternationBrush3}" />
            </Trigger>
        </Style.Triggers-->
    </Style>

    <!-- DataGrid -->

    <Style x:Key="{x:Type dg:DataGrid}" TargetType="{x:Type dg:DataGrid}">
        <Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="AlternationCount" Value="2" />
        <Setter Property="BorderBrush" Value="{StaticResource SolidBorderBrush}" />
        <Setter Property="HorizontalGridLinesBrush" Value="#999" />
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type dg:DataGrid}">
                    <Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}">
                        <ScrollViewer Focusable="false" Name="DG_ScrollViewer">
                            <ScrollViewer.Template>
                                <ControlTemplate TargetType="{x:Type ScrollViewer}">
                                    <Grid>
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="Auto"/>
                                            <RowDefinition Height="*"/>
                                            <RowDefinition Height="Auto"/>
                                        </Grid.RowDefinitions>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="Auto"/>
                                            <ColumnDefinition Width="*"/>
                                            <ColumnDefinition Width="Auto"/>
                                        </Grid.ColumnDefinitions>
                                        <Border Grid.ColumnSpan="3" Background="{StaticResource LightBrush}" BorderBrush="{StaticResource NormalBorderBrush}" BorderThickness="0,1" />
                                        <Button Command="{x:Static dg:DataGrid.SelectAllCommand}" Width="{Binding RelativeSource={RelativeSource AncestorType={x:Type dg:DataGrid}}, Path=RowHeaderActualWidth}" Focusable="false" OverridesDefaultStyle="True" Visibility="{Binding RelativeSource={RelativeSource AncestorType={x:Type dg:DataGrid}}, Path=HeadersVisibility, Converter={x:Static dg:DataGrid.HeadersVisibilityConverter}, ConverterParameter={x:Static dg:DataGridHeadersVisibility.All}}">
                                            <Button.Template>
                                                <ControlTemplate TargetType="{x:Type Button}">
                                                    <Grid>
                                                        <Border Background="{StaticResource LightBrush}" BorderBrush="{StaticResource NormalBorderBrush}" BorderThickness="0,1">
                                                            <Path x:Name="Arrow" VerticalAlignment="Bottom" Margin="4" Fill="#3000" Width="11" Height="11" Stretch="Fill" Data="M1,0 L1,1 0,1 z"/>
                                                        </Border>
                                                        <!--Rectangle Width="1" Fill="#AAC377" HorizontalAlignment="Right" />
                                                        <Rectangle Width="1" Margin="0,0,1,0" Fill="#425B10" HorizontalAlignment="Right" /-->
                                                    </Grid>
                                                </ControlTemplate>
                                            </Button.Template>
                                        </Button>
                                        <dgp:DataGridColumnHeadersPresenter Grid.Column="1" Visibility="{Binding RelativeSource={RelativeSource AncestorType={x:Type dg:DataGrid}}, Path=HeadersVisibility, Converter={x:Static dg:DataGrid.HeadersVisibilityConverter}, ConverterParameter={x:Static dg:DataGridHeadersVisibility.Column}}"/>
                                            <ScrollContentPresenter Grid.Row="1" Grid.ColumnSpan="2" CanContentScroll="{TemplateBinding CanContentScroll}" />
                                        <ScrollBar Name="PART_VerticalScrollBar" Grid.Row="1"  Grid.Column="2"  Orientation="Vertical" Maximum="{TemplateBinding ScrollableHeight}" ViewportSize="{TemplateBinding ViewportHeight}" Value="{Binding Path=VerticalOffset, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}" Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"/>
                                        <Grid Grid.Row="2" Grid.Column="1">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="{Binding RelativeSource={RelativeSource AncestorType={x:Type dg:DataGrid}}, Path=NonFrozenColumnsViewportHorizontalOffset}"/>
                                                <ColumnDefinition Width="*"/>
                                            </Grid.ColumnDefinitions>
                                            <ScrollBar Grid.Column="1" Name="PART_HorizontalScrollBar" Orientation="Horizontal" Maximum="{TemplateBinding ScrollableWidth}" ViewportSize="{TemplateBinding ViewportWidth}" Value="{Binding Path=HorizontalOffset, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}" Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"/>
                                        </Grid>
                                    </Grid>
                                </ControlTemplate>
                            </ScrollViewer.Template>
                            <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                        </ScrollViewer>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property="IsGrouping" Value="true">
                <Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
            </Trigger>
        </Style.Triggers>
    </Style>




</ResourceDictionary>
